/**
 * 通知日志管理初始化
 */
var NotifyRecordLog = {
    id: "NotifyRecordLogTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
NotifyRecordLog.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '商户编号', field: 'merchantNo', visible: true, align: 'center', valign: 'middle'},
            {title: '商户订单号', field: 'outOrderNo', visible: true, align: 'center', valign: 'middle'},
            {title: '平台订单号', field: 'platTradeNo', visible: true, align: 'center', valign: 'middle'},
            {title: '请求信息', field: 'request', visible: true, align: 'center', valign: 'middle'},
            {title: '返回信息', field: 'response', visible: true, align: 'center', valign: 'middle'},
            {title: 'HTTP状态', field: 'httpStatus', visible: true, align: 'center', valign: 'middle'},
            {title: '通知类型', field: 'notifyType', visible: true, align: 'center', valign: 'middle',formatter:"notifyTypeFormatter"},
            {title: '创建时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'},
            {title: '更新时间', field: 'updateTime', visible: true, align: 'center', valign: 'middle'}
    ];
};


function notifyTypeFormatter(value, row, index){
	if (value == 100) {
		return '<span class="label label-success">自动</span>';
	} else if(value == 101){
		return '<span class="label label-danger">手动</span>';
	}
}

/**
 * 检查是否选中
 */
NotifyRecordLog.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        NotifyRecordLog.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加通知日志
 */
NotifyRecordLog.openAddNotifyRecordLog = function () {
    var index = layer.open({
        type: 2,
        title: '添加通知日志',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/notifyRecordLog/notifyRecordLog_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看通知日志详情
 */
NotifyRecordLog.openNotifyRecordLogDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '通知日志详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/notifyRecordLog/notifyRecordLog_update/' + NotifyRecordLog.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除通知日志
 */
NotifyRecordLog.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/notifyRecordLog/delete", function (data) {
            Feng.success("删除成功!");
            NotifyRecordLog.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("notifyRecordLogId",this.seItem.id);
        ajax.start();
    }
};

NotifyRecordLog.formParams = function() {
    var queryData = {};
    queryData['merchantNo'] = $("#merchantNo").val();
    queryData['outOrderNo'] = $("#outOrderNo").val();
    queryData['platTradeNo'] = $("#platTradeNo").val();

    return queryData;
}

/**
 * 查询交易流水列表
 */
NotifyRecordLog.search = function () {
	
	NotifyRecordLog.table.refresh({query: NotifyRecordLog.formParams()});
};



$(function () {
    var defaultColunms = NotifyRecordLog.initColumn();
    var table = new BSTable(NotifyRecordLog.id, "/notifyRecordLog/list", defaultColunms);
    table.setPaginationType("server");//服务器端分页
    table.setQueryParams(NotifyRecordLog.formParams());
    NotifyRecordLog.table = table.init();
});
